import 'package:flutter/material.dart';
import '../../../widgets/card.dart';

class InformationPage extends StatelessWidget {
  const InformationPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context);
    final primaryColor = theme.primaryColor;
    return Scaffold(
      appBar: AppBar(
        title: Text('资讯',style: TextStyle(color: Colors.white)),
        backgroundColor: primaryColor,
      ),
      body: Container(
        color: Colors.grey[50],
        child: Padding(
          padding: const EdgeInsets.all(16),
          child: GridView.builder(
            gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
              crossAxisCount: 2, // 一排两个
              crossAxisSpacing: 6, // 水平间距
              mainAxisSpacing: 6, // 垂直间距
              childAspectRatio: 0.75, // 卡片宽高比
            ),
            itemCount: _mockNewsData.length,
            itemBuilder: (context, index) {
              return NewsCard(
                newsItem: _mockNewsData[index],
                onTap: () {
                  // 点击卡片的处理逻辑
                  _onNewsCardTap(context, _mockNewsData[index]);
                },
              );
            },
          ),
        ),
      ),
    );
  }

  /// 点击资讯卡片的处理
  void _onNewsCardTap(BuildContext context, NewsItem newsItem) {
    ScaffoldMessenger.of(context).showSnackBar(
      SnackBar(
        content: Text('点击了: ${newsItem.title}'),
        duration: const Duration(seconds: 2),
      ),
    );
  }

  /// 模拟资讯数据
  static final List<NewsItem> _mockNewsData = [
    NewsItem(
      id: '1',
      imageUrl: 'https://picsum.photos/300/200?random=1',
      title: 'Flutter 3.0 正式发布',
      description: 'Google 发布了 Flutter 3.0，带来了更多新特性和性能优化，支持更多平台开发。',
      tag: '技术',
      date: DateTime.now().subtract(const Duration(hours: 2)),
    ),
    NewsItem(
      id: '2',
      imageUrl: 'https://picsum.photos/300/200?random=2',
      title: 'Dart 语言最新更新',
      description: 'Dart 语言迎来重大更新，新增多项语法糖和性能改进，开发体验更佳。',
      tag: '开发',
      date: DateTime.now().subtract(const Duration(hours: 5)),
    ),
    NewsItem(
      id: '3',
      imageUrl: 'https://picsum.photos/300/200?random=3',
      title: '移动应用开发趋势',
      description: '2024年移动应用开发的最新趋势分析，跨平台开发成为主流选择。',
      tag: '趋势',
      date: DateTime.now().subtract(const Duration(days: 1)),
    ),
    NewsItem(
      id: '4',
      imageUrl: 'https://picsum.photos/300/200?random=4',
      title: 'UI设计最佳实践',
      description: '现代移动应用UI设计的最佳实践指南，提升用户体验的关键要素。',
      tag: '设计',
      date: DateTime.now().subtract(const Duration(days: 2)),
    ),
    NewsItem(
      id: '5',
      imageUrl: 'https://picsum.photos/300/200?random=5',
      title: '性能优化技巧',
      description: 'Flutter应用性能优化的实用技巧，让你的应用运行更流畅。',
      tag: '优化',
      date: DateTime.now().subtract(const Duration(days: 3)),
    ),
    NewsItem(
      id: '6',
      imageUrl: 'https://picsum.photos/300/200?random=6',
      title: '开源项目推荐',
      description: '本周精选的优秀Flutter开源项目，值得学习和参考的代码实现。',
      tag: '开源',
      date: DateTime.now().subtract(const Duration(days: 4)),
    ),
    NewsItem(
      id: '7',
      imageUrl: 'https://picsum.photos/300/200?random=7',
      title: '状态管理方案对比',
      description: 'Provider、Bloc、Riverpod等状态管理方案的详细对比分析。',
      tag: '架构',
      date: DateTime.now().subtract(const Duration(days: 5)),
    ),
    NewsItem(
      id: '8',
      imageUrl: 'https://picsum.photos/300/200?random=8',
      title: '测试驱动开发',
      description: 'Flutter项目中如何实施测试驱动开发，提高代码质量和可维护性。',
      tag: '测试',
      date: DateTime.now().subtract(const Duration(days: 6)),
    ),
  ];
}